<template>
	<view>
		<web-view :src="url"></web-view>
		<view class="next_box" v-if="quotationFile">
			<view class="next" @tap="wordView">下一步</view>
		</view>
	</view>
</template>

<script>
	import {toast} from '@/common/public.js'
	import {mixins} from '@/common/mixins.js'
	export default {
		mixins:[mixins],
		data() {
			return {
				url: '',
				quotationFile:'',
				trfId:'',
				weUserId:'',
				entry:2
			};
		},
		onLoad(option){
			//867d324cfc47269f1114b906cc190a2f
			this.trfId = option.trfId || ''
			// oovO-5xBKxK7ozWIQMkVgJ7oQOPI
			if(uni.getStorageSync('sgs_userId')) {
				this.initData()
			} else {
				this.wxAuth()
			}
		},
		methods:{
			initData() {
				this.weUserId = uni.getStorageSync('sgs_userId')
				uni.showLoading({
					title:'加载中...'
				})
				this.selectQuotationInfoByTrfId()
			},
			selectQuotationInfoByTrfId() {
				let param = {
					trfId:this.trfId,
					weUserId:this.weUserId
				}
				this.$api.selectQuotationInfoByTrfId(param).then(res=>{
					if (res.code == 200) {
						this.quotationFile = res.data.quotationFile
						this.downloadByCloudID()
					} else {
						uni.hideLoading()
						toast(res.msg)
					}
				})
			},
			downloadByCloudID() {
				let param = {
					systemID:1,
					networkType:2,
					hash:new Date().getTime(),
					cloudID:this.quotationFile.cloudId
				}
				this.$api.downloadByCloudID(param).then(res=>{
					if (res) {
						let link = res.replace(/\s*/g,'')
						let fileUrl = encodeURIComponent(link)
						let fileName = this.quotationFile.fileName
						let url = this.baseUrl+'/api/sgs-mart/afl/trf/fileDownload?fileUrl='+fileUrl+'&fileUrlName='+fileName
						uni.downloadFile({
						    url: url, //仅为示例，并非真实的资源
						    success: (res) => {
								if (res.statusCode === 200) {
									uni.hideLoading()
									this.url = `/hybrid/html/pdf.html?url=${res.tempFilePath}`
								}
						    },
							fail:()=>{
								uni.hideLoading()
							}
						});
					} else {
						uni.hideLoading()
						toast(res.msg)
					}
				})
			},
			wordView() {
				uni.navigateTo({
					url:`/pages/wordView/wordView?trfId=${this.trfId}`
				})
			}
		},
		onBackPress(){}
	}
</script>

<style scoped>
	.next_box{
		position: fixed;
		left:0;
		bottom:0;
		z-index:9999999;
		width:100%;
		padding:20rpx;
		box-sizing: border-box;
		background-color: #fff;
	}
	.next{
		width: 300rpx;
		height: 70rpx;
		text-align: center;
		line-height: 70rpx;
		margin: 0 auto;
		color: #fff;
		font-size: 26rpx;
		background-color: #ff6600;
	}
</style>
